package com.code.offer;

import java.util.HashSet;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/7/22 12:06
 *
 *  桶排序 或者使用 hashset
 *
 */
public class The3 {
    public int findRepeatNumber(int[] nums) {
        if (nums == null || nums.length < 1) return 0;
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if (!set.contains(nums[i])) {
                set.add(nums[i]);
            } else {
                return nums[i];
            }
        }
        return 0;
    }

    public int findRepeatNumberT(int[] nums) {

        int[] temp = new int[nums.length];
        for(int i = 0;i < nums.length;i++) {
            temp[nums[i]]++;
            if(temp[nums[i]]>1)
                return nums[i];
        }
        return -1;

    }
}
